var resourceCtrl  = new XFApp.client();
XFApp.client.prototype.resource = {
    successCode : "10000",
    page : null,
    urlItems : {
        queryDataURL : basePath+"/chart/order/buyerData"
    },
    setChart: function(result){
        var myChart = echarts.init(document.getElementById('main'));
        //--- 折柱 ---
       // var myChart = ec.init(document.getElementById('main'));
        var option = {
            tooltip : {
                trigger: 'axis'
            },
            toolbox: {
                show : true,
                feature : {
                    mark : {show: true},
                    dataView : {show: true, readOnly: false},
                    magicType: {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            legend: {
                data:['买单数','客单价（USD）']
            },
            xAxis : [
                {
                    type : 'category',
                    data : []
                }
            ],
            yAxis : [
                {
                    type : 'value',
                    name : '客单价',
                    axisLabel : {
                        formatter: '${value}'
                    }
                },
                {
                    type : 'value',
                    name : '买单数',
                    axisLabel : {
                        formatter: '{value}'
                    }
                }
            ],
            series : [
                {
                    name:'买单数',
                    type:'bar',
                    barWidth : 40,
                    itemStyle:{
                        normal:{
                            color:'#2980b9'
                        }
                    },
                    yAxisIndex: 1,
                    data:[]
                },
                {
                    name:'客单价（USD）',
                    type:'line',
                    itemStyle:{
                        normal:{
                            color:'#bd2c30'
                        }
                    },
                    data:[]
                }
            ]
        };
        for(var i = 0; i < result.length; i++){
            option.xAxis[0].data.push(result[i].name);
            option.series[0].data.push(result[i].value1);
            option.series[1].data.push(result[i].value2);
        }
        myChart.setTheme('macarons');
        myChart.setOption(option);

    },
    chart : function(){
        _this = this;
        $.ajax({
            url:_this.urlItems.queryDataURL,
            data:{month:6},
            type:'get',
            cache:false,
            dataType:'json',
            success:function(data) {
                if(true == data.isSuccess){
                    var result = data.result;
                    _this.setChart(result);
                }
            },
            error : function() {
                window.webDialogUtil.alert("提示","操作失败");
            }
        });
    },
    event : function(){
        _this = this;

        $("#searchButton").on("click",function(){
            _this.chart();
        });

    }
};
$(function(){
    resourceCtrl.resource.chart();
    resourceCtrl.resource.event();
});